<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Dpb_model extends CI_Model
{
    
    function __construct()
    {
       parent::__construct();
		$this->CI = get_instance();
    }//end of function

    function add_dpb($data){
        
        $this->db->insert('PEIL_BANJIR',$data);
        
    }//end of function
    
    function edit_dpb($id_dpb,$data){
        
        $this->db->where('IDPEIL_BANJIR',$id_dpb);
        $this->db->update('PEIL_BANJIR',$data);        
        
    }//end of function
    
    function delete_dpb($dpb_id){
		$data = array(
			'STATUS' => 0
		);
		$this->db->where('IDPEIL_BANJIR',$dpb_id);
		$this->db->update('PEIL_BANJIR',$data);
	}

    function get_dpb(){
        
        $this->db->select('*');
        $this->db->from('PEIL_BANJIR');
        $this->db->where('STATUS > 0');
        $query = $this->db->get();
        return $query;        
        
    }//end of function
    
	function get_id_dpb($id_dpb){
		$this->db->select('*');
		$this->db->from('PEIL_BANJIR');
		$this->db->where('IDPEIL_BANJIR',$id_dpb);
		$query = $this->db->get();
		return $query;
	}

	function get_all_dpb_thn($tahun){
		$this->db->select('*');
		$this->db->from('PEIL_BANJIR');
		$this->db->where('TAHUN', $tahun);
		$this->db->where('STATUS',1);

		return $this->db->get()->result();
	}

	function get_all_dpb_cari($tahun,$kecamatan){
		$this->db->select('*');
		$this->db->from('PEIL_BANJIR');
		$this->db->where('TAHUN', $tahun);
		$this->db->where('KECAMATAN', $kecamatan);
		
		return $this->db->get()->result();
	}
	
	function get_dpb_grid(){	
		$this->db->select('*');
		$this->db->from('PEIL_BANJIR');
		$this->db->where("STATUS > 0 ");
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('*');
		$this->db->from('PEIL_BANJIR');
		$this->db->where("STATUS > 0 ");
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}
	
	function get_all_kecamatan(){
		$this->db->select('*');
		$this->db->from('KECAMATAN');
		$this->db->where('STATUS',1);
		
		return $this->db->get();
	}

	function get_kecamatanID($id_kecamatan){
		$this->db->select('*');
		$this->db->from('KECAMATAN');
		$this->db->where('IDKECAMATAN',$id_kecamatan);
		$query = $this->db->get();
		return $query;
	}
	
	function get_all_kelurahan(){
		$this->db->select('*');
		$this->db->from('KELURAHAN');
		$this->db->where('STATUS',1);
		
		return $this->db->get();
	}
	
	function get_klr_by_kcm($kcm){
		$this->db->select('*');
		$this->db->from('KELURAHAN');
		$this->db->where('IDKECAMATAN', $kcm);
		$this->db->where('STATUS', 1);
		
		return $this->db->get();
	}
	
}//end of class